package starter.actions;

/**
 * @ClassName appiumtest
 * @Date 2024/10/11 15:45 52
 * @Author Jack Chen
 * @Description serenity-cucumber-page-objects-starter-master
 * @Version 1.0
 */

import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.Arrays;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;

public class appiumtest {

    private AndroidDriver driver;
    @Before
    public void setUp() {
        var options = new BaseOptions()
                .amend("appium:deviceName", "RedMiNote 11T pro")
                .amend("appium:automationName", "UiAutomator2")
                .amend("platformName", "Android")
                .amend("appium:ensureWebviewsHavePages", true)
                .amend("appium:nativeWebScreenshot", true)
                .amend("appium:newCommandTimeout", 3600)
                .amend("appium:connectHardwareKeyboard", true);

        driver = new AndroidDriver(this.getUrl(), options);
    }


    private URL getUrl() {
        try {
            return new URL("http://127.0.0.1:4723");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Test
    public void sampleTest() {
        WebElement aliAppBtn = driver.findElement(By.xpath("//android.widget.ImageView[@content-desc='阿里云盘']"));
        aliAppBtn.click();
    }

    @After
    public void tearDown() {
        driver.quit();
    }

}
